

/** 求和 */
 const array = [1, 2, 3, 4];


 /** for循环 */
 var func1 = () => {
    let ret = 0;
    for (let i = 0; i < array.length; i++) {
        ret += array[i];
    }
    console.info(ret)
    return ret;
}

/** reducer */
var func2 = () => {
    var reducer = (accumulator, currentValue) => accumulator + currentValue;
    array.reduce(reducer); // 没有初始值，默认第0个为初始值
}




/** ------------------------------------------ */
// 下面函数依次执行

function f1(arg) {
    console.info("f1", arg);
    return arg;
}
function f2(arg) {
    console.info("f2", arg);
    return arg;
}
function f3(arg) {
    console.info("f3", arg);
    return arg;
}

// 1.直接执行
f1("omg");
f2("omg");
f3("omg");

// 2.链式,容易进入嵌套低于，洋葱模型
f3(f2(f1("omg")));

// 3.聚合
 compose(f1, f2, f3)("omg")
function compose(...funcs) {
    // funcs = [f1, f2, f3]
    return funcs.reduce((a, b) => (...args) => a(b(...args)));
}



